<?php
$maxRows_rs_resource = 50;
$pageNum_rs_resource = 0;
if (isset($_GET['pageNum_rs_resource'])) {
    $pageNum_rs_resource = $_GET['pageNum_rs_resource'];
}
$startRow_rs_resource = $pageNum_rs_resource * $maxRows_rs_resource;


$rs_resource = getResourceListDesc($startRow_rs_resource, "NO");
$row_rs_resource = mysql_fetch_assoc($rs_resource);

if (isset($_GET['tt'])) {
    $tt = $_GET['tt'];
} else {
    $all_rs_resource = getResourceListDesc("", "YES");
    $tt = mysql_num_rows($all_rs_resource);
}
$totalPages_rs_resource = ceil($tt / $maxRows_rs_resource) - 1;

$queryString_rs_resource = "";
$pg = 0;
if (!empty($_SERVER['QUERY_STRING'])) {
    $params = explode("&", $_SERVER['QUERY_STRING']);
    $newParams = array();
    foreach ($params as $param) {
        if (stristr($param, "pg") == false &&
                stristr($param, "tt") == false) {
            array_push($newParams, $param);
        }
    }
    if (count($newParams) != 0) {
        $queryString_rs_resource = "&" . htmlentities(implode("&", $newParams));
    }
}
$queryString_rs_resource = sprintf("&tt=%d%s", $tt, $queryString_rs_resource);
?>
<form id="resource_view" method="post" name="resource_view">
    <table border="0">
        <tr>
            <td><?php if ($pg > 0) { // Show if not first page  ?>
                    <a href="<?php printf("%s?pg=%d%s", $currentPage, 0, $queryString_rs_resource); ?>">First</a>
<?php } // Show if not first page  ?></td>
            <td><?php if ($pg > 0) { // Show if not first page
?>
                <a href="<?php printf("%s?pg=%d%s", $currentPage, max(0, $pg - 1), $queryString_rs_resource); ?>">Previous</a>
                <?php } // Show if not first page ?></td>
            <td><?php if ($pg < $totalPages_rs_resource) { // Show if not last page  ?>
                    <a href="<?php printf("%s?pg=%d%s", $currentPage, min($totalPages_rs_resource, $pg + 1), $queryString_rs_resource); ?>">Next</a>
                <?php } // Show if not last page ?></td>
            <td><?php if ($pg < $totalPages_rs_resource) { // Show if not last page  ?>
                    <a href="<?php printf("%s?pg=%d%s", $currentPage, $totalPages_rs_resource, $queryString_rs_resource); ?>">Last</a>
                <?php } // Show if not last page ?></td>
            <td>&nbsp;
                Records <?php echo ($startRow_rs_resource + 1) ?> to <?php echo min($startRow_rs_resource + $maxRows_rs_resource, $tt) ?> of <?php echo $tt ?></td>
            <td><label>
                    <input type="submit" name="button" id="button" value="Approve" onclick="document.getElementById('frmaction').value='approve'" />
                </label>
                <input type="submit" name="button2" id="button2" value="Delete" onclick="document.getElementById('frmaction').value='delete'; return confirm('Do YOU really want to delete this Item as it might delete other sub Item');" />
                <input type="hidden" name="frmaction" id="frmaction" />
                <input name="frmCont" type="hidden" id="frmCont" value="resource" />
                <input name="chkprefix" type="hidden" id="chkprefix" value="delchk" /></td>
        </tr>
    </table>
    <table width="100%" border="0" cellpadding="0" cellspacing="0" id="datatable">
        <tr>
            <th align="left">ID</th>
            <th align="left">Category</th>
            <th align="left">Location</th>
            <th align="left">Description</th>
            <th valign="middle">Action
                <input type="checkbox" name="delchk_0" id="delchk_0" onchange="checkUncheck('resource_view','delchk')"  /></th>
        </tr>
        <?php do {
 ?>
                    <tr>
                        <td><?php echo $row_rs_resource['resource_id']; ?></td>
                        <td><a href="pages/resource_edit.php?aj&itemid=<?php echo $row_rs_resource['resource_id']; ?>"  rel="facebox"><?php echo $row_rs_resource['category_name']; ?></a></td>
                        <td><a href="<?php echo "../resources/" . $row_rs_resource['resource_url']; ?>" rel="facebox"><?php echo $row_rs_resource['resource_url'];
                    if ($row_rs_resource['category_id'] == 7) { ?>
                                    <img name="" src="../resources/thump.php?im=<?php echo $row_rs_resource['resource_url']; ?>" alt="" /><?php } ?>
                            </a></td>
                        <td><?php echo $row_rs_resource['resource_description']; ?></td>
                        <td valign="middle"><input type="checkbox" name="delchk_<?php echo $row_rs_resource['resource_id']; ?>" id="delchk_<?php echo $row_rs_resource['resource_id']; ?>"  value="<?php echo $row_rs_resource['resource_id']; ?>"/></td>
                    </tr>
<?php } while ($row_rs_resource = mysql_fetch_assoc($rs_resource));
                mysql_free_result($rs_resource); ?>
    </table>
</form>